﻿// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.



using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity;
using IdentityModel;
using Wlmy.Ids4.Model;
using Wlmy.Ids4.Model.Model;

namespace Wlmy.Ids4
{
    public static class Config
    {
        public static IEnumerable<IdentityResource> IdentityResources =>
            new IdentityResource[]
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResources.Address(),
                new IdentityResources.Phone(),
                new IdentityResources.Email(),
                new IdentityResource("custom","公共信息",new string[]{JwtClaimTypes.Role,JwtClaimTypes.Profile,JwtClaimTypes.Address,JwtClaimTypes.PhoneNumber,JwtClaimTypes.NickName,JwtClaimTypes.Email})
            };
        public static IEnumerable<ApiResource> ApiResource =>
            new ApiResource[]
            {
                new ApiResource{ Scopes=new List<string>{ "PesonalWebsite.Api" },Name="PesonalWebsite.Api",DisplayName="个人网站Api",UserClaims=new List<string>{ "role"}},
            };

        public static IEnumerable<Client> Clients =>
            new Client[]
            { new Client{
                ClientName="Wlmy.Ids4.Vue",
                ClientId="Wlmy.Ids4.Vue",
                ClientUri="http://localhost:8080",
                RedirectUris=new List<string>
                {
                    "http://localhost:8080",
                    "http://localhost:8080/#/main",
                    "http://localhost:8080/#/login",
                    "http://localhost:8080/#/callback",
                    "http://localhost:8080/callback.html"
                },
                AllowedScopes=new HashSet<string>{ "openid","custom" },
                AllowedGrantTypes = GrantTypes.Code ,
                ClientSecrets = new List<Secret>{
                    new Secret("Wlmy.Ids4.Vue".Sha256(), "Wlmy.Ids4.Vue")
                },
                RequireClientSecret = false,
                AllowOfflineAccess = true,
                RefreshTokenUsage = TokenUsage.ReUse,
                AllowedCorsOrigins = new List<string>(){ "http://localhost:8080" },
                PostLogoutRedirectUris= new List<string>{ "http://localhost:8080/#/main" }
            },

               new IdentityServer4.Models.Client{
                   ClientName="PesonalWebsite.Vue",
                   RedirectUris=new List<string>{"http://localhost:7000/" },
                   ClientId=Guid.NewGuid().ToString(),
                   ClientUri="http://192.168.168.6:7000/",
                   AllowedScopes=new HashSet<string>{ "PesonalWebsite.Api" },
                   AllowedGrantTypes = GrantTypes.Implicit,ClientSecrets = new List<Secret>
                   {
                       new Secret("PesonalWebsite.Vue".Sha256(), "PesonalWebsite.Vue")
                   },
                   AllowedCorsOrigins = new List<string>(){ "http://192.168.168.6:7000" }
               }
            };
        public static List<ApiScope> ApiScopes => new List<ApiScope> { new ApiScope { Name = "PesonalWebsite.Api", DisplayName = "个人网站Api" } };
        public static Role Role => new Role { Id = 1, Name = "admin" };
        //密码:123qwe
        public static User User => new User
        {
            NickName = "妄揽明月",
            UserName = "admin",
            PasswordHash = @"AQAAAAEAACcQAAAAEFaX8CMbgXN+UlY9Rv0YnnlYRimaHkt1BbuhCXY3/Q8rDehrHc//LuVd2S7Unx8ObA==",
            Email = "798513422@qq.com",
            Id = 1,
            NormalizedUserName = "ADMIN",
            UserRoles = new List<UserRole> 
            { 
                new UserRole 
                { 
                    UserId = 1, 
                    RoleId = 1
                }
            },
            Claims = new List<UserClaim>
            {
                new UserClaim
                {   UserId = 1,
                    ClaimType = JwtClaimTypes.Role,
                    ClaimValue = "管理员" 
                },
                new UserClaim
                {   UserId = 1,
                    ClaimType = JwtClaimTypes.NickName,
                    ClaimValue = "妄揽明月"
                },
                new UserClaim
                {   UserId = 1,
                    ClaimType = JwtClaimTypes.Name,
                    ClaimValue = "admin"
                },
            }
        };

    }
}